Skip to content

fix(objectql): a committed or rolled-back trio handle reads as closed - #35541

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35149-trio-handle-closed
Nov 19, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35149-trio-handle-closed

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb
Fixes #35149

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:脚本里手动开启的事务提交或回滚之后,仍带着这个旧事务的迟到写入会像普通写入一样正常落库,不再被塞进一个已经结束的事务。
  • 为什么做:两种事务结束后的行为原本不一致,另一种早已按“已关闭即视为没有事务”处理,这次让两者一致。
  • 出错会怎样:最坏情况是某次迟到写入没有进入它本应加入的仍在进行的事务;改动只在事务已提交或已回滚之后生效,事务进行中的行为不变。
  • 要你做什么:无,席位落地。

席位核对

What changes

  • engine-execute-transactions.ts: the trio's commit/rollback release is now closeTrioTransactionScope, which drops the owner record (as before) AND adds the handle to a module-level closedTrioHandles WeakSet, only for a handle the trio itself opened (one with an owner record). isClosedTrioHandle reads it. recordTrioTransactionScope clears the mark, so a driver that hands the same object out on a later beginTransaction gets it back open.
  • engine-transactions-section.ts isClosedUnitHandle: when openedUnits holds no entry for the handle, it answers isClosedTrioHandle(handle). An openedUnits entry still decides first, so a transaction() unit handle reads exactly as before.
  • engine-scoped-context.ts: commitTransaction / rollbackTransaction call closeTrioTransactionScope in their existing finally. A joined (ambient) handle still returns early and is never marked.
  • engine.ts untouched: 6852 lines at origin/main 9212119 and at head (facade ceiling 6854).
  • Every reader of isClosedUnitHandle now treats a closed trio handle as absent, as objectql: ScopedContext.transaction() publishes an ambient transaction entry it never closes, so an async hook's later write inside it is lost ("Transaction query already complete") #22855 does for a closed unit: buildDriverOptions, enforceTransactionOrigin, opensAfterAbortUnit, the secret-row release, the summary write transaction, and openTransactionKind ('separate' becomes 'none' for a closed trio handle).
  • Clause-② measured on the diff: no caller that got an answer now gets a refusal. A late write carrying a closed trio handle was never refused (unattributed handle, the gate declined to judge), and is not refused now; it runs unenrolled instead of being handed the dead handle.

Tests

packages/objectql/src/engine-transaction-same-origin.test.ts:

  • The PR fix(objectql)!: an action body's write inside ctx.api.transaction keeps its audit rows beside a telemetry datasource #35102 pins "forgets the owner once the trio commits / rolls back" are re-worded to "treats the handle as closed once the trio commits / rolls back — a late cross-datasource write runs unenrolled". Intent kept (the record does not outlive the handle; the late write lands, not refused); the assertion now also requires ledgerDb.writes[0].transaction to be undefined.
  • New top-level describe a trio handle closes as a transaction() unit handle does (#35149), in the same harness file: parity with a closed transaction() unit handle on a late cross-datasource write; a late same-datasource write after rollback runs unenrolled; CONTROL (open trio handle reads open, enrolls, and a cross-datasource business write under it is still refused with ERR_CROSS_DATASOURCE_TRANSACTION_WRITE); openTransactionKind separate-then-none; a reused driver handle reads open on its next begin.

Acceptance notes

  • A0, reproduced at origin/main 9212119 source with the new tests only: a late ledger insert carrying a committed trio handle reached ledger_db with transaction: { __trx: 'primary' } (the dead foreign handle); the same after rollback. 7 failed / 27 passed.
  • The ADR-0119 note (2026-11-18) says the owner record is "dropped when commitTransaction or rollbackTransaction closes it": still true, and its "a handle the engine never opened" limit now matches the code. No ADR edit.

Verification

Red at origin/main source, green at head, ablations
  • Red (tests only, source at 9212119): vitest run src/engine-transaction-same-origin.test.ts → Tests 7 failed | 27 passed (34); first failure expected { __trx: 'primary' } to be undefined.
  • Green at b548ddf: same file plus engine-scoped-transaction-late-write.test.ts and open-transaction.test.ts → Test Files 3 passed (3), Tests 69 passed (69).
  • Ablation 1 (scripts/ablation-replace.mjs, anchor x1 → x0, blob abff61612cfc → 235b522e2582): close drops the record without marking → Tests 7 failed | 27 passed (34); restored, blob == HEAD, git diff HEAD empty.
  • Ablation 2 (anchor x1 → x0, blob abff61612cfc → 99010386c306): recordTrioTransactionScope no longer clears the mark → Tests 1 failed | 33 passed (34) (the reused-handle pin); restored, blob == HEAD, git diff HEAD empty.
  • The test imports ./engine.js from src, so no dist leg applies.
Package and gates at b548ddf
  • pnpm --filter @objectstack/objectql typecheck && pnpm --filter @objectstack/objectql test under the verify lock → VERDICT command-exit 0; Test Files 615 passed (615), Tests 13900 passed (13900); check:test-typecheck: OK.
  • dispatch-gates.mjs --commands derived 65 families: 59 ran locally, exit 0 each. check:type-check-debt exit 3 (its closure build never got a turn on the shared verify lock): NOT MEASURED. check:dts-closure, check:dual-build-cjs-loads, check:lean-entry-closure, check:published-files and check:sourcemap-no-sources-content read the built dist; the objectql build did not get a turn on the lock after more than 45 minutes in the queue, so these are NOT MEASURED locally, a declared narrowing, and left to CI.
  • test:repo, --project integration and the dogfood battery not run locally: not owed for this diff (no !, no narrowing arm), declared to CI.

Generated by Claude Code

The ScopedContext trio now marks the handles it opened closed on commit and
rollback, and isClosedUnitHandle answers true for them, so late work carrying
one runs unenrolled, as late work carrying a closed transaction() unit
handle does.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

9 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json b68f9ae34734879aee2d57438da3b606f6f97bd7 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from a506fa70a6cab50004c70ae1f1cddcb32122f043 — the merge of head b548ddfb97074ff1d2b822f3cd98172789b03acf into base b68f9ae34734879aee2d57438da3b606f6f97bd7, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a506fa70a6cab50004c70ae1f1cddcb32122f043 && git checkout a506fa70a6cab50004c70ae1f1cddcb32122f043
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b68f9ae34734879aee2d57438da3b606f6f97bd7 b548ddfb97074ff1d2b822f3cd98172789b03acf && git checkout -B drift-repro b68f9ae34734879aee2d57438da3b606f6f97bd7 && git merge --no-ff b548ddfb97074ff1d2b822f3cd98172789b03acf

node scripts/docs-audit/affected-docs.mjs --json b68f9ae34734879aee2d57438da3b606f6f97bd7

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CXsZsKmgG1EcKp5bY4

维护者速读

  • 用户能看到什么变化:脚本里手动开启并已提交或回滚的事务,之后若还有迟到的写入带着它,现在按"不在事务中"正常写入,不再被交给一个已经结束的事务。
  • 为什么做:以前这种迟到写入会被塞进已失效的事务连接,跨库时也不会被拦下,行为不可预测;另一种事务写法早已这样处理,这次让两者一致。
  • 出错会怎样:只影响事务结束后才到达的写入;事务进行中的写入和跨库拒绝都不变。
  • 要你做什么:无。区域审核通过后自行落地。
  • 席位意见:改动小而对称,复用已有的"已关闭"判断,证据充分,可以落地。

席位核对

L1-a: ACCEPT · head b548ddfb97074ff1d2b822f3cd98172789b03acf · Fixes #35149 · 2026-11-19T15:22Z · reviewed to pm-dispatch text at origin/main fca72dfa32

Readings, my own: check-governed-merges --pr 35541 0 of 5 paths governed; merge-tree against main clean; K=14 (<15, no merge owed); CI 37 success / 16 skipped / 0 failed; +133/−12. The claim (7010907655, 13:43Z) predates the 14:38Z p1-only rule, so this p2 is in flight. All files are inside the claimed surface, and engine.ts is untouched. The pins are a card-named top-level describe in engine-transaction-same-origin.test.ts, the file holding the #35102 pins the claim names, rather than a new file. That keeps one shared harness; no amendment is owed.

Code.

  • closeTrioTransactionScope adds the handle to the WeakSet only when trioTransactionScopes.delete(handle) returned true. So only a handle the trio itself opened can be marked closed, and a foreign handle is left as it was.
  • recordTrioTransactionScope clears the mark, so a driver that reuses the handle object reads as open again.
  • isClosedUnitHandle consults the trio mark only when openedUnits has no entry. A transaction() unit's own verdict is unchanged, and a detached handle still short-circuits first.
  • The import is one-way (engine-transactions-section → engine-execute-transactions, which imports neither the section nor unit-detach), so no cycle is added.

Every reader of isClosedUnitHandle treats "closed" as absent and falls back to the ambient transaction or none, never to a refusal. I checked driverOptions, the cross-datasource write check, secret-field release, writeTransactionOf/summaries, opensAfterAbortUnit and openTransactionKind. So a closed trio handle now gets exactly the closed-unit treatment from #22855.

Pins (names grepped).

  • The two fix(objectql)!: an action body's write inside ctx.api.transaction keeps its audit rows beside a telemetry datasource #35102 cells are renamed to treats the handle as closed once the trio commits / rolls back and now also assert the late write carries no transaction.
  • The new describe a trio handle closes as a transaction() unit handle does (#35149) has five cells:
    • parity of the late cross-datasource write against a closed unit handle;
    • the late same-datasource write runs unenrolled, never on the dead handle;
    • CONTROL: an open trio handle still enrolls, and a cross-datasource write under it is still refused ERR_CROSS_DATASOURCE_TRANSACTION_WRITE;
    • body-door parity, separate while open and none once committed;
    • the reused handle reads as open on its next begin.
  • A0 (late ledger insert handed the dead primary handle), the two ablations (7 red, 1 red) and the objectql suite (13900 passed) are from os-dev-report 7012990620.

Declaration: agreed. Clause-②: no / Metadata-protocol: none / @objectstack/objectql patch. No accepted input gains a refusal: the cross-datasource refusal still fires only under an open handle, and the late write now succeeds unenrolled where it was handed a dead handle. openTransactionKind moves from 'separate' to 'none' for a closed trio handle, within its existing union. That is the correct answer for a finished transaction, and the body doors then pass no dead handle. The changeset states it. No L2 is owed.

Gates. 5 dist-reading gates and check:type-check-debt were not run locally (the lock was busy); CI's green covers them on this head.

Routing. Not governed and no contract face: data-1 lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Landing · area data-1 · 2026-11-19T15:23Z

reading value
L1-a ACCEPT 7013453714 at b548ddfb97, with no L2 owed
Head b548ddfb97, CI green (37 success / 16 skipped / 0 failed); K=14, so no merge is owed; merge-tree against main clean
check-governed-merges --pr 35541 0 of 5 paths governed; engine.ts untouched (6852, ceiling 6854)
Declaration Clause-②: no / Metadata-protocol: none / @objectstack/objectql patch (agreed by L1-a)

State: draft → ready + auto-merge (merge queue). #35149 closes on merge via Fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objectql: a committed trio handle reverts to unattributed instead of closed

2 participants